from coin.exchange.bithumb.kr_ws.ws_client import BithumbWSClient
from coin.exchange.bithumb.kr_ws.feed_client import BithumbWsFeedBase
from coin.exchange.coinone_v2.kr_ws.ws_client import CoinoneWSClient
from coin.exchange.coinone_v2.kr_ws.feed_client import CoinoneWsFeedBase
from coin.exchange.upbit_v1.kr_ws.ws_client import UpbitWSClient
from coin.exchange.upbit_v1.kr_ws.feed_client import UpbitWsFeedBase


def generate_ws_feed_client(market_type, exchange, api_version, product, feed_handler):
  # in the order of exchange from coin_proto
  if exchange == "Bithumb":
    assert api_version is None
    return BithumbWSClient(BithumbWSClient.RequestType.FromSingleProduct(product), feed_handler)
  elif exchange == "Coinone":
    assert api_version == "v2" or api_version is None
    return CoinoneWSClient(CoinoneWSClient.RequestType.FromSingleProduct(product), feed_handler)
  elif exchange == "Upbit":
    assert api_version == "v1" or api_version is None
    return UpbitWSClient(UpbitWSClient.RequestType.FromSingleProduct(product), feed_handler)
  else:
    raise NotImplementedError(exchange)


def generate_ws_feed_subscriber(market_type, exchange, api_version, product):
  # in the order of exchange from coin_proto
  if exchange == "Bithumb":
    assert api_version is None
    return BithumbWsFeedBase(product)
  elif exchange == "Coinone":
    assert api_version == "v2" or api_version is None
    return CoinoneWsFeedBase(product)
  elif exchange == "Upbit":
    assert api_version == "v1" or api_version is None
    return UpbitWsFeedBase(product)
  else:
    raise NotImplementedError(exchange)
